@extends('layouts.app')

@section('content')
    {{--<div data-options="region:'center'"  class="easy_center">
        <div id="tt" class="easyui-tabs" style="width:100%;" data-options="border:false,fit:true,plain:true">
            <div title="首页"></div>
        </div>
    </div>--}}
    <div class="main-content">
        <div class="search_inp">
            <table width="100%" border="1" class="table_search">
                <thead>
                <tr>
                    <th colspan="6">
                        <span>查询条件</span>
                    </th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td width="13.33%" align="right"><label>重点级别：</label></td>
                    <td width="20%">
                        <select name="jibie" class="w150">
                            <option value="">请选择重点级别</option>
                            <option value="0">一般单位</option>
                            <option value="1">省级重点单位</option>
                            <option value="2">市级重点单位</option>
                            <option value="3">县区级重点单位</option>
                        </select>
                    </td>
                    <td width="13.33%" align="right"><label>企业类型：</label></td>
                    <td width="20%">
                        <select name="type" class="w150">
                            <option value="">请选择企业类型</option>
                            @foreach($type as $v)
                                <option value="{{$v->id}}">{{$v->name}}</option>
                            @endforeach
                        </select>
                    </td>
                    <td width="13.33%" align="right"><label>企业性质：</label></td>
                    <td width="20%">
                        <select name="xingzhi" class="w150">
                            <option value="">请选择企业性质</option>
                            <option value="国有">国有</option>
                            <option value="私有">私有</option>
                            <option value="股份">股份</option>
                            <option value="合资">合资</option>
                            <option value="外资">外资</option>
                            <option value="个体">个体</option>
                            {{--@foreach($type as $v)

                                <option value="{{$v->id}}">{{$v->name}}</option>
                            @endforeach--}}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td width="13.33%" align="right"><label>单位名称：</label></td>
                    <td width="50%" colspan="3"><input type="text" class="" name="name" placeholder="请输入单位关键字" style="width: 78.5%"/></td>
                    {{--<td width="13.33%" align="right"><label>是否认领：</label></td>
                    <td width="20%">
                        <select name="is_renling" class="w150">
                            <option value="">请选择是否认领</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </td>--}}
                    <td width="13.33%" align="right"></td>
                    <td width="20%">
                        <input type="hidden" name="city" value=""/>
                        <input type="hidden" name="area" value=""/>
                        <input type="hidden" name="org_id" value=""/>
                        <a href="javascript:" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:80px;margin-left: 60px" onclick="doSearch()">查询</a>
                    </td>

                </tr>
                </tbody>
            </table>
        </div>
        <div class="btn-toolbar list-toolbar">
            <div class="form-all mg_t30">
                <div id="tb">
                    <a class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="huifu()">恢复</a>
                    <a class="easyui-linkbutton" iconCls="icon-cancel" plain="true" onclick="cancel()">彻底删除</a>
                </div>
                <table id="dg" title="已注销单位查询" class="easyui-datagrid" style="width:100%;height:600px"
                       data-options="rownumbers:true,singleSelect:true,pagination:true,pageSize:20,url:'{{url('admin/units/closed')}}',method:'get',toolbar:'#tb'">
                    <thead>
                    <tr>
                        <th data-options="field:'city'" width="5%" align="center">市</th>
                        <th data-options="field:'area'" width="10%" align="center">区</th>
                        <th data-options="field:'org_id'" width="10%" align="center">所属派出所</th>
                        <th data-options="field:'is_imp'" width="5%" align="center">重点级别</th>
                        <th data-options="field:'type'" width="12%" align="center">企业类型</th>
                        <th data-options="field:'xingzhi'" width="8%" align="center">企业性质</th>
                        <th data-options="field:'name'" width="15%" align="center">单位名</th>
                        <th data-options="field:'address'" width="15%" align="center">详细地址</th>
                        <th data-options="field:'frdb_name'" width="10%" align="center">联系人</th>
                        <th data-options="field:'frdb_phone'" width="11%" align="center">联系电话</th>
                        {{--<th data-options="field:'id',formatter:formatAction" width="10%" align="center">操作</th>--}}
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>

    <!--新增-->
    <div id="w" class="easyui-window" closed="true" style="width:1400px;height:650px;padding:10px;">

    </div>
    <!--编辑-->
    <!--注销-->
    <div id="dlg" class="easyui-dialog" title="删除" closed="true" style="width:400px;height:200px;line-height:100px;text-align:center;font-size:16px;padding:10px">
        您确定要彻底删除该单位？
    </div>

    <div id="dlg2" class="easyui-dialog" title="恢复" closed="true" style="width:400px;height:200px;line-height:100px;text-align:center;font-size:16px;padding:10px">
        您确定要恢复该单位？
    </div>
    <!--设为重点单位-->
    <div id="unit" class="easyui-dialog" data-options="closed:true,iconCls:'icon-save'" style="width:300px;height:150px;padding:10px;">
        <form id="unit_form" method="post">
            <table>
                <tr>
                    <td width="60" align="right">级 别：&nbsp;&nbsp;&nbsp;&nbsp;</td>
                    <td>
                        <select class="easyui-combobox" name="is_imp" id="is_imp" style="width:200px;">
                            <option value="0">取消重点</option>
                            <option value="1">省级</option>
                            <option value="2">市级</option>
                            <option value="3">县级</option>
                            <option value="4">乡级</option>
                        </select>
                    </td>
                </tr>
            </table>
        </form>
    </div>

    <div id="menu" class="easyui-menu" style="width:200px;">
        <div onclick="huifu()" iconCls="icon-edit">恢复</div>
        <div onclick="cancel()" iconCls="icon-cancel">彻底删除</div>
    </div>

    <script type="text/javascript">
        /*function formatAction(value,row,index){
         return '<a href="'+'edit/'+value+'" target="_blank">编辑</a>';
         }*/
        /*window.onload = function(){
         doSearch();
         }*/
        //搜索
        function doSearch(){
            $('#dg').datagrid('load',{
                city: $("input[name='city']").val(),
                area: $("input[name='area']").val(),
                org_id: $("input[name='org_id']").val(),
                name: $("input[name='name']").val(),
                type: $("select[name='type']").val(),
                xingzhi: $("select[name='xingzhi']").val(),
                jibie:$("select[name='jibie']").val(),
            });
        }


        function load_city_data_from_menu($id){
            $('#dg').datagrid('load',{
                city: $id,
            });
            $("input[name='city']").val($id);
            //$("input[name='area']").val('');
            //$("input[name='org_id']").val('');
        }

        function load_area_data_from_menu($id){
            $('#dg').datagrid('load',{
                area: $id,
            });
            //$("input[name='city']").val('');
            $("input[name='area']").val($id);
            //$("input[name='org_id']").val('');
        }
        function load_org_data_from_menu($id){
            $('#dg').datagrid('load',{
                org_id: $id,
            });
            //$("input[name='city']").val('');
            //$("input[name='area']").val('');
            $("input[name='org_id']").val($id);
        }
    </script>

    <script type="text/javascript">
        function huifu(){
            var row = $('#dg').datagrid('getSelected');
            if (row) {
                $('#dlg2').dialog({
                    title: "恢复",
                    closed: false,
                    modal:true,
                    buttons: [{
                        text: '确定',
                        iconCls: 'icon-ok',
                        handler: huifu2
                    }, {
                        text: '取消',
                        iconCls: 'icon-cancel',
                        handler: function () {
                            $('#dlg2').dialog('close');
                        }
                    }]
                });
            } else {
                $.messager.alert('提示','请选中要编辑的行！');
            }
        }
        function huifu2(){
            $('#dlg2').dialog('close');
            var row = $('#dg').datagrid('getSelected');
            var url = 'huifu/'+row.id;
            $.ajax({
                type: 'get',
                url: url,
                success: function(data){
                    if(data.status == 1){
                        $.messager.alert('信息提示',data.msg,'info');
                        $('#dlg').dialog('close');
                        var rowIndex = $('#dg').datagrid('getRowIndex', row);
                        $('#dg').datagrid('deleteRow', rowIndex);
                    }else{
                        $.messager.alert('信息提示',data.msg,'info');
                    }
                }
            });
        }

        function cancel(){
            var row = $('#dg').datagrid('getSelected');
            if (row) {
                $('#dlg').dialog({
                    title: "删除",
                    closed: false,
                    modal:true,
                    buttons: [{
                        text: '确定',
                        iconCls: 'icon-ok',
                        handler: del
                    }, {
                        text: '取消',
                        iconCls: 'icon-cancel',
                        handler: function () {
                            $('#dlg').dialog('close');
                        }
                    }]
                });
            } else {
                $.messager.alert('提示','请选中要编辑的行！');
            }
        }
        function del(){
            $('#dlg').dialog('close');
            var row = $('#dg').datagrid('getSelected');
            var url = 'del/'+row.id;
            $.ajax({
                type: 'get',
                url: url,
                success: function(data){
                    if(data.status == 1){
                        $.messager.alert('信息提示',data.msg,'info');
                        $('#dlg').dialog('close');
                        var rowIndex = $('#dg').datagrid('getRowIndex', row);
                        $('#dg').datagrid('deleteRow', rowIndex);
                    }else{
                        $.messager.alert('信息提示',data.msg,'info');
                    }
                }
            });
        }



        $("#dg").datagrid({
            onRowContextMenu: function (e, rowIndex, rowData) {
                e.preventDefault();
                $(this).datagrid("clearSelections");
                $(this).datagrid("selectRow", rowIndex);
                $('#menu').menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });
                e.preventDefault();
            }
        });
    </script>

@stop
